home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / UVisualEffect (PP) / UVisualEffect.sit / UVisualEffect / UVisualEffect.cp < prev    next >
Text File  |  1995-08-23  |  6KB  |  209 lines

  1. // ===========================================================================
  2. //    UVisualEffect.cp                ⌐ 1995, âric Forget. All rights reserved.
  3. // ===========================================================================
  4. //    
  5. //    ************************************************************************
  6. //    *                                                                      *
  7. //    *    Before using this code you should read the "License Agreement"     *
  8. //    *    document and agree with it.                                        *
  9. //    *                                                                      *
  10. //    ************************************************************************
  11. //    
  12. //    UVisualEffect help you doing the "visual effect" like in the Finder
  13. //    when you open or close a file/folder.
  14. //
  15. // ---------------------------------------------------------------------------
  16. //    Instructions Notes:
  17. //    ------------------
  18. //
  19. //    There is two methods:
  20. //    
  21. //    1)  (a) Call one of the two SetFirstXXX() method
  22. //        (b) Call one of the two SetLastXXX() method
  23. //        (c) Call DoPlayEffects()
  24. //        Note that XXX should not necessary be the same for both (a) and (b)
  25. //
  26. //    2)    (a) Call either SetRects() or SetPanes()
  27. //        (b) Call DoPlayEffects()
  28. //
  29. // ---------------------------------------------------------------------------
  30.  
  31.  
  32. #include    "UVisualEffect.h"
  33.  
  34.  
  35.  
  36.  
  37. // ---------------------------------------------------------------------------
  38. //        Ñ Constantes
  39. // ---------------------------------------------------------------------------
  40.  
  41. const    Rect    Rect_Undefined                    = { -1, -1, -1, -1 };
  42.  
  43.  
  44. // ---------------------------------------------------------------------------
  45. //        Ñ Initialisation
  46. // ---------------------------------------------------------------------------
  47.  
  48. Int16    UVisualEffect::sNbrStep                 = 4;
  49. Rect    UVisualEffect::sFirstRect                = Rect_Undefined;
  50. Rect    UVisualEffect::sLastRect                = Rect_Undefined;
  51.  
  52.  
  53. // ---------------------------------------------------------------------------
  54. //        Ñ Initialize
  55. // ---------------------------------------------------------------------------
  56.  
  57. void
  58. UVisualEffect::Initialize(
  59.     Int16        inNbrStep)
  60. {
  61.     sNbrStep = inNbrStep;
  62.     sFirstRect = Rect_Undefined;
  63.     sLastRect = Rect_Undefined;
  64. }
  65.  
  66.  
  67. // ---------------------------------------------------------------------------
  68. //        Ñ SetFirstRect
  69. // ---------------------------------------------------------------------------
  70.  
  71. void
  72. UVisualEffect::SetFirstRect(
  73.     Rect        inFirstRect)
  74. {
  75.     sFirstRect = inFirstRect;
  76. }
  77.  
  78.  
  79. // ---------------------------------------------------------------------------
  80. //        Ñ SetFirstPane
  81. // ---------------------------------------------------------------------------
  82.  
  83. void
  84. UVisualEffect::SetFirstPane(
  85.     LPane        *inFirstPane)
  86. {
  87.     SetFirstRect(CalcGlobalPaneFrame(inFirstPane));
  88. }
  89.  
  90.  
  91. // ---------------------------------------------------------------------------
  92. //        Ñ SetLastRect
  93. // ---------------------------------------------------------------------------
  94.  
  95. void
  96. UVisualEffect::SetLastRect(
  97.     Rect        inLastRect)
  98. {
  99.     sLastRect = inLastRect;
  100. }
  101.  
  102.  
  103. // ---------------------------------------------------------------------------
  104. //        Ñ SetLastPane
  105. // ---------------------------------------------------------------------------
  106.  
  107. void
  108. UVisualEffect::SetLastPane(
  109.     LPane        *inLastPane)
  110. {
  111.     SetLastRect(CalcGlobalPaneFrame(inLastPane));
  112. }
  113.  
  114.  
  115. // ---------------------------------------------------------------------------
  116. //        Ñ SetRects
  117. // ---------------------------------------------------------------------------
  118.  
  119. void
  120. UVisualEffect::SetRects(
  121.     Rect        inFirstRect,
  122.     Rect        inLastRect)
  123. {
  124.     SetFirstRect(inFirstRect);
  125.     SetLastRect(inLastRect);
  126. }
  127.  
  128.  
  129. // ---------------------------------------------------------------------------
  130. //        Ñ SetPanes
  131. // ---------------------------------------------------------------------------
  132.  
  133. void
  134. UVisualEffect::SetPanes(
  135.     LPane        *inFirstPane,
  136.     LPane        *inLastPane)
  137. {
  138.     SetFirstPane(inFirstPane);
  139.     SetLastPane(inLastPane);
  140. }
  141.  
  142.  
  143. // ---------------------------------------------------------------------------
  144. //        Ñ CalcGlobalPaneFrame
  145. // ---------------------------------------------------------------------------
  146.  
  147. Rect
  148. UVisualEffect::CalcGlobalPaneFrame(
  149.     LPane        *inPane)
  150. {
  151.     Rect        frame;
  152.     
  153.     
  154.     inPane->CalcPortFrameRect(frame);
  155.     
  156.     inPane->PortToGlobalPoint(topLeft(frame));
  157.     inPane->PortToGlobalPoint(botRight(frame));
  158.     
  159.     return frame;
  160. }
  161.  
  162.  
  163. // ---------------------------------------------------------------------------
  164. //        Ñ DoPlayEffects
  165. // ---------------------------------------------------------------------------
  166.  
  167. void
  168. UVisualEffect::DoPlayEffects()
  169. {
  170.     if (!::EqualRect(&sFirstRect, &Rect_Undefined) &&
  171.         !::EqualRect(&sLastRect, &Rect_Undefined)) {
  172.     
  173.         GrafPtr        theScreen = UScreenPort::GetScreenPort();
  174.         Int32        finalTick;
  175.         Rect        stepRect, tempRect;
  176.         
  177.         
  178.         LView::OutOfFocus(nil);
  179.         SetPort(theScreen);
  180.         
  181.         stepRect.top    = (sLastRect.top    - sFirstRect.top   ) / (sNbrStep + 2);
  182.         stepRect.left    = (sLastRect.left   - sFirstRect.left  ) / (sNbrStep + 2);
  183.         stepRect.bottom = (sLastRect.bottom - sFirstRect.bottom) / (sNbrStep + 2);
  184.         stepRect.right    = (sLastRect.right  - sFirstRect.right ) / (sNbrStep + 2);
  185.         
  186.         
  187.         ::PenPat(&UQDGlobals::GetQDGlobals()->gray);
  188.         ::PenMode (patXor);
  189.         
  190.         for(Int16 j = 0; j < 2; j++) {
  191.         
  192.             tempRect = sFirstRect;
  193.             
  194.             for(Int16 i = 0; i < (sNbrStep + 2); i++) {
  195.                 
  196.                 ::FrameRect(&tempRect);
  197.                 ::Delay(1, &finalTick);
  198.                 tempRect.top    += stepRect.top;
  199.                 tempRect.left   += stepRect.left;
  200.                 tempRect.bottom += stepRect.bottom;
  201.                 tempRect.right  += stepRect.right;
  202.             }
  203.             ::Delay(4, &finalTick);
  204.         }
  205.     }
  206.     
  207.     // Reset initial value
  208.     Initialize();
  209. }